<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>外卖超级助手</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/style/login.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/style/css/bootstrap.min.css">
<script
	src="${pageContext.request.contextPath}/js/lib/jquery-1.9.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/lib/jquery.md5.js"></script>
<script src="${pageContext.request.contextPath}/js/lib/bootstrap.min.js"></script>
<script
	src="${pageContext.request.contextPath}/js/lib/bootstrap-bootbox/bootbox.min.js"></script>
<script src="${pageContext.request.contextPath}/js/src/navtive.js"
	type="text/javascript"></script>
</head>

<body style="background-color: #15B4A2;">

	<div id="login" class="container">
		<div class="row">
<!-- 			<div class="alert alert-success" style="padding: 10px; width: 280px;"> -->
<!-- 				如果您还没注册，请进行注册》<a -->
<%-- 					href="${pageContext.request.contextPath}/admin/register_e.do">注册</a> --%>
<!-- 			</div> -->
			<div class="formParent">
				<div id="loginForm" class="loginForm">
					<form id="form">
						<input type="hidden" name="appType" value="appc">
						<div class="loginName">
							<label>用户名</label> <input type="text" value="" class="userName"
								name="username">
						</div>
						<div class="loginPassword">
							<label>密码</label> <input type="password" class="password"
								name="pwd" value="">
						</div>
						<!-- 					<div style="padding-top: 10px;"> -->
						<!-- 						<input type="text" size="4" style="height: 17px;" name="vcode" -->
						<!-- 							class="validateCode"> <img alt="" -->
						<%-- 							src="${pageContext.request.contextPath}/verify.do" --%>
						<!-- 							style="cursor: pointer;" id="verify"> <a -->
						<!-- 							href="javascript:void(0);" id="refresh">看不清楚?</a> -->
						<!-- 					</div> -->
						<div class="loginBtn">
							<input type="checkbox" name="remenber" value="1" class="remenber">
							<span>记住我的登录信息</span> <input type="button" value="登录"
								class="btn btn-primary" id="btn" style="height: 30px;margin-left: 70px;">
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
<script>
	$("#verify").click(
			function() {
				$(this).attr(
						"src",
						"${pageContext.request.contextPath}/verify.do?random="
								+ Math.random());
			})

	$("#refresh").click(
			function() {
				$("#verify").attr(
						"src",
						"${pageContext.request.contextPath}/verify.do?random="
								+ Math.random());
			})

	$(document).keydown(function(ev) {
		if (ev.which == 13) {
			var $_userName = $(".userName");
			var $_password = $(".password");
			var tip = "";
			if ($_userName.val() == "") {
				tip = "账号不能为空";
				bootbox.alert(tip);
				return;
			} else if ($_password.val() == "") {
				tip = "密码不能为空";
				bootbox.alert(tip);
				return;
			}
			login($_userName.val(), $_password.val())
		}
	});
	$("#btn").click(function() {
		var $_userName = $(".userName");
		var $_password = $(".password");
		var tip = "";
		if ($_userName.val() == "") {
			tip = "账号不能为空";
			bootbox.alert(tip);
			return;
		} else if ($_password.val() == "") {
			tip = "密码不能为空";
			bootbox.alert(tip);
			return;
		}
		login($_userName.val(), $.md5($_password.val()))
	});

	function login(username, pwd) {
		var remenber = 0;

		if ($('.remenber').is(':checked')) {
			remenber = 1;
		}
		var params = {
			"username" : username,
			"pwd" : pwd,
			"remenber" : remenber
		};
		$
				.ajax({
					url : "${pageContext.request.contextPath}/admin/login.do",
					type : "post",
					dataType : "json",
					data : params,
					async : false,
					success : function(data) {
						if (data.flag == 1) {
							var url = "${pageContext.request.contextPath}/admin/index.do";
							window.location = url;
							var user = JSON.stringify(params);
							nativeSaveUserInfo(user);
							alert(user);
						} else {
							bootbox.alert(data.tip);
						}
					},
					error : function() {
						bootbox.alert("ajax错误");
					}
				});
	}

	function appLogin(content) {
		if (content != "false") {
			var user = JSON.parse(content);
			$(".userName").val(user.username);
			$(".password").val(user.pwd);
			$(".remenber").attr("checked", true);
			login(user.username, user.pwd);
		} else {
			$("#login").show();
		}
	}
</script>
